package com.example.jung_week3_adepter;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity implements OnClickListener{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		findViewById(R.id.button5).setOnClickListener(this);
		findViewById(R.id.button6).setOnClickListener(this);
		findViewById(R.id.button7).setOnClickListener(this);
		findViewById(R.id.button8).setOnClickListener(this);
		findViewById(R.id.button9).setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		
		return true;
	}
	
	final int List = 101;
	final int Grid = 102;
	final int Spinner = 103;
	final int Gallery = 104;
	
	
	public void fncListView(View v){
		Intent intent = new Intent();
		intent.setClass(getApplicationContext(), ListViewActivity.class);		
		//startActivity(intent);	
		startActivityForResult(intent, 101);
	}
	
	public void fncGridView(View v){
		Intent intent = new Intent();
		intent.setClass(getApplicationContext(), GridViewActivity.class);
		//startActivity(intent);
		startActivityForResult(intent, 102);
	}
	
	public void fncSpinnerView(View v){
		Intent intent = new Intent();
		intent.setClass(getApplicationContext(), SpinnerViewActivity.class);
		//startActivity(intent);
		startActivityForResult(intent, 103);
	}

	public void fncGallaryView(View v){		
		Intent intent = new Intent();
		intent.setClass(getApplicationContext(), GallaryViewActivity.class);
		//startActivity(intent);
		startActivityForResult(intent, 104);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch(requestCode){
		case List :
			if(resultCode == Activity.RESULT_OK){
				int img = data.getIntExtra("img",0);
				findViewById(R.id.button1).setBackgroundResource(img);
			}		
			
			break;
		case Grid :
			if(resultCode == Activity.RESULT_OK){
				int img = data.getIntExtra("img",0);
				findViewById(R.id.button2).setBackgroundResource(img);
			}
			
			break;
		case Spinner : 
			if(resultCode == Activity.RESULT_OK){
				int img = data.getIntExtra("img",0);
				findViewById(R.id.button3).setBackgroundResource(img);
			}
			
			
			break;			
		case Gallery :
			if(resultCode == Activity.RESULT_OK){
				int img = data.getIntExtra("img",0);
				findViewById(R.id.button4).setBackgroundResource(img);
			}
			
			
			break;
		}
		
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent = new Intent();
		int action = 0;
		Uri uri = null;
		switch(v.getId()){		
			case R.id.button5 : // call phone
				intent.setAction(Intent.ACTION_CALL);
				intent.setData(Uri.parse("tel:111-2222-3333"));
				startActivity(intent);
				break;
			case R.id.button6 : // send sms
				intent.setAction(Intent.ACTION_SENDTO);
				intent.setData(Uri.parse("sms:000-5555-4444"));
				startActivity(intent);
				break;
			case R.id.button7 : //view contact
				intent.setAction(Intent.ACTION_DIAL);
				intent.setData(Uri.parse("content://contacts/people/1"));
				startActivity(intent);
				break;
			case R.id.button8 : // make mp3
				intent.setAction(Intent.ACTION_GET_CONTENT);
				intent.setType("audio/*");
				startActivity(intent);			
				break;
			case R.id.button9 : //youtube
				intent.setAction(Intent.ACTION_VIEW);
				intent.setData(Uri.parse("http://youtu.be/792jeZ08h94"));
				startActivity(intent);
				break;
		
		}
	}
}
